/*
 * Copyright (c) 2011-2012 Alexander Dubu
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * o  Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * o  Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * o  Neither the name Axil nor the names of its contributors may be used to
 *    endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package axil.api.access;

/**
 * A class for defining a field in a host application object that will be
 * accessible to an Axil script. This mechanism is provided for manually
 * setting up the accessibility when the annotation or interface-based mechanisms
 * are not practical. Typically, this is only used when a type for which the
 * source code is not available or cannot be altered needs to be accessible.
 *
 * @see axil.api.Axil#access(Class, FieldDefinition...)
 */
public class FieldDefinition {
	private String field;
	private String accessor;
	private String[] aliases;


	/**
	 * Define a field in a host application object that will be accessible to
	 * an Axil script.
	 *
	 * @param field
	 * 	The name of the field as an Axil identifier. This is the name by which
	 * 	it will be referenced in a script. Note that the name transformation
	 * 	rules are not applied.
	 *
	 * @param accessor
	 * 	The field or method to be used as the mechanism for accessing the value.
	 * 	If the given string ends with "()", then it is assumed to be a method.
	 * 	If not, then it is assumed to be a field to be directly accessed.
	 * 	Regardless, the field or method can be private and still be accessible
	 * 	to Axil.
	 *
	 * @param aliases
	 * 	A set of optional aliases by which the field can also be referenced.
	 * 	This is provided either as a convenience mechanism for the script writer
	 * 	or as a mechanism for providing backwards compatibility with older
	 * 	scripts which may use different identifiers.
	 */
	public FieldDefinition(String field, String accessor, String... aliases) {
		this.field = field;
		this.accessor = accessor;
		this.aliases = aliases;
	}


	/**
	 * The name of the field as an Axil identifier. This is the name by which
	 * 	it will be referenced in a script.
	 *
	 * @return
	 * 	Returns the Axil identifier.
	 */
	public String field() {
		return field;
	}


	/**
	 * The field or method to be used as the mechanism for accessing the value.
	 * If the given string ends with "()", then it is assumed to be a method.
	 * If not, then it is assumed to be a field to be directly accessed.
	 *
	 * @return
	 * 	Returns the access mechanism.
	 */
	public String accessor() {
		return accessor;
	}


	/**
	 * Get the set of optional aliases by which the field can also be referenced.
	 * This is provided either as a convenience mechanism for the script writer
	 * or as a mechanism for providing backwards compatibility with older
	 * scripts which may use different identifiers.
	 *
	 * @return
	 * 	Returns the set of aliases. The array returned may be empty but never
	 * 	null.
	 */
	public String[] aliases() {
		return aliases;
	}
}
